@extends('public.layouts')
@section('style')
    <meta name="_token" content="{{ csrf_token() }}"/>
    <style>
        .project-th {
            text-align: center;
        }

        .patent-td {
            text-align: center;
        }
    </style>
    <link rel="stylesheet" href="{{asset('admin_assets/css/bootstrap-datetimepicker.min.css')}}">
    <link rel="stylesheet" href="{{url('admin_assets/css/ip.css')}}">
    <link rel="stylesheet" href="{{url('css/search.css')}}">
    <link rel="stylesheet" href="{{url('admin_assets/css/fileinput.min.css')}}">
@stop
@section('content')
    <div class="content-wrapper" style="background-color: white">
        <section id="list" class="content">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="box box-info"
                         style="padding-top: 0px;margin-top: 0px;border-top: 0px;border-bottom: solid 1px #0080ff;">
                        <div class="box-body" style="">
                            <div class="row">
                                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="margin-top: 0.5vw">
                                    <a href="#" title="返回首页" style="float: left"><i class="fa fa-home fa-2x"
                                                                                    style="width: 100%;color: #009aff">
                                        </i></a>
                                    <a href="#"><span
                                                style="font-size: 20px;float: left;color: #009aff">&nbsp;我的项目</span></a>
                                    <div class="clear"></div>
                                </div>
                                <div class="col-lg-5 col-md-8 col-sm-12 col-xs-12 col-lg-offset-5 col-md-offset-2 btn-div">
                                    <button type="button" class="btn btn-info div-btn" data-toggle="modal"
                                            data-target="#modal-addProject"
                                            style="background: #009aff;float: right;margin-left: 1%;margin-top: 1%">新增项目
                                    </button>
                                    <button type="button" class="btn btn-info div-btn" data-toggle="modal"
                                            data-target="#modal-batchImportProject"
                                            style="background: #009aff;float: right;margin-left: 1%;margin-top: 1%">批量导入
                                    </button>
                                    {{--<form action="{{url('user/mine/myProjectSearch')}}" method="post"--}}
                                          {{--enctype="multipart/form-data" class="search">--}}
                                        {{--{{csrf_field()}}--}}
                                        {{--<button class="fa fa-search fa-lg"></button>--}}
                                        {{--<input type="search" class="search" value="{{$keywords}}" id="search-input"--}}
                                               {{--name="search">--}}
                                    {{--</form>--}}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            @include('public/alert')
            <div class="row" style="margin-top: 2%">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th class="project-th">序号</th>
                                <th class="project-th">申请人</th>
                                <th class="project-th">类型</th>
                                <th class="project-th">公司成立时间</th>
                                <th class="project-th">公司注册区</th>
                                <th class="project-th">申请日期</th>
                                <th class="project-th">通过日期</th>
                                <th class="project-th">进度</th>
                                <th class="project-th">证书有效期</th>
                                <th class="project-th">报件资料</th>
                                <th class="project-th">附件资料</th>
                                <th class="project-th">操作</th>
                            </tr>
                            </thead>
                            <tbody class="list">
                            @if($product->isEmpty())
                                <tr>
                                    <td class="patent-td" colspan="13"><h3 align="center">暂无数据</h3></td>
                                </tr>
                            @else
                                @foreach($product as $k =>$v)
                                    <tr>
                                        <td class="patent-td" style="vertical-align: middle">{{$k+1}}</td>
                                        <td class="patent-td applicant" style="vertical-align: middle">{{$v['applicant']}}</td>
                                        <td class="patent-td com" style="vertical-align: middle">{{$v['company']}}</td>
                                        <td class="patent-td secondType"
                                            style="vertical-align: middle">{{$v['SecondType']['name']}}</td>
                                        <td class="patent-td registration_time"
                                            style="vertical-align: middle">{{date("Y-m-d",strtotime($v['registration_time']))}}</td>
                                        <td class="patent-td registration_area"
                                            style="vertical-align: middle">{{$v['registration_area']}}</td>
                                        <td class="patent-td created_at"
                                            style="vertical-align: middle">{{date("Y-m-d",strtotime($v['created_at']))}}</td>
                                        <td class="patent-td authority_time"
                                            style="vertical-align: middle">
                                            @if(!empty($v['authority_time']))
                                                {{date("Y-m-d",strtotime($v['authority_time']))}}
                                            @endif
                                        </td>
                                        <td class="patent-td Progress" style="vertical-align: middle">
                                            @if($v['Progress']->isEmpty())
                                                已完成
                                            @else
                                                @if($v['Progress']->last()['is_renew'])
                                                    @if($progress[$v['Progress']->last()['progress_list_id']]['flag'])
                                                        已完成
                                                    @else
                                                        未完成
                                                    @endif
                                                @else
                                                    {{$progress[$v['Progress']->last()['progress_list_id']]['name']}}
                                                @endif
                                            @endif
                                        </td>
                                        <td class="patent-td date"
                                            style="vertical-align: middle">
                                            @if(!empty($v['authority_time']))
                                                {{date("Y-m-d",strtotime("+".$v['FirstType']['time']." year",strtotime($v['authority_time'])))}}
                                            @endif
                                        </td>
                                        <td class="patent-td file" style="vertical-align: middle">
                                            @if(empty($v['file']))
                                                未上传
                                            @else
                                                <a href="{{asset('Uploads/resources/'.$v['file'])}}">
                                                    查看资料
                                                </a>
                                            @endif
                                            <a href="#" data-toggle="modal" product="{{$v['id']}}"
                                               onclick="setReport($(this))"
                                               data-target="#uploadReport">
                                                @if(empty($v['file']))
                                                    上传
                                                @else
                                                    重新上传
                                                @endif
                                            </a>
                                        </td>
                                        <td class="patent-td is_download_notice" style="vertical-align: middle">
                                            @if($v['is_download_notice']==0)
                                                <a href="#" data-toggle="modal" product="{{$v['id']}}"
                                                   onclick="se($(this))" data-target="#modal-official-document">上传资料</a>
                                            @else
                                                <a href="#" data-toggle="modal" product="{{$v['id']}}"
                                                   onclick="se($(this))" data-target="#modal-official-document">上传资料</a>
                                                <a href="#" product="{{$v['id']}}" onclick="s($(this));"
                                                   data-toggle="modal" data-target="#modal-download-file">下载资料</a>
                                                <textarea style="display: none">{{json_encode($v['Files'])}}</textarea>
                                            @endif
                                        </td>
                                        <td class="patent-td" style="vertical-align: middle">
                                            <a href="#" data-toggle="modal" product="{{$v['id']}}"
                                               typea="{{$v['SecondType']['id']}}" applicant="{{$v['applicant']}}"
                                               name="{{$v['name']}}" number="{{$v['number']}}" onclick="setV($(this))"
                                               data-target="#modal-project-renew">代缴年费&nbsp;</a>
                                            @if($v['Progress']->isNotEmpty())
                                                @if($v['is_download_notice']==3)
                                                    等待邮寄
                                                @elseif($v['is_download_notice']==4)
                                                    <a href="#" rel="{{$v['tracking_number']}}" onclick="ss($(this));" data-toggle="modal" data-target="#modal-tracking-number">查看单号</a>
                                                @else
                                                    @if( !empty($v['Progress']->first()))
                                                        <a href="#" onclick="set($(this))"
                                                           pid="{{ $v['Progress']->first()['id'] }}"
                                                           address="{{empty($v['User'])?"":$v['User']['address']}}"
                                                           rel="{{$v['id']}}" data-toggle="modal"
                                                           data-target="#user-address">&nbsp;申请纸质通知书&nbsp;</a>
                                                    @endif
                                                @endif

                                            @endif
                                            <a href="{{url('user/mine/delProduct',['id'=>$v['id']])}}"
                                               onclick="return confirm('确定要删除吗?');">&nbsp;删除</a>
                                        </td>
                                    </tr>
                                @endforeach
                            @endif
                            </tbody>
                        </table>
                        {{--<div class="">--}}
                        {{--{!! $product->links() !!}--}}
                        {{--</div>--}}
                    </div>
                </div>
            </div>
        </section>
    </div>
    @include('public.addProjectModal')
    @include('public.batchImportProjectModal')
    @include('public.projectRenewModal')
    @include('public.userAddress')
    @include('public.download-fileModal')
    @include('public.trackingNumberModal')
@stop
@section('javascript')
    <script src="{{asset('admin_assets/js/bootstrap-datetimepicker.min.js')}}"></script>
    <script src="{{asset('js/ip.js')}}"></script>
    <script src="{{asset('js/list.min.js')}}"></script>
    <script src="{{asset('admin_assets/js/fileinput.min.js')}}"></script>
    <script src="{{asset('admin_assets/js/fileinput_locale_zh.js')}}"></script>
    <script>
        var options = {
            valueNames: ['applicant','com', 'secondType', 'registration_time', 'registration_area', 'created_at', 'authority_time', 'Progress', 'date', 'is_download_notice']
        };
        var List = new List('list', options);
        $(".form_datetime").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss",
            autoclose: true,
            todayBtn: true,
            minuteStep: 10,
            language: "en"
        });
        List.search($('#search-input').val());
        $("#inputFile").fileinput({
            language: 'zh',
            autoReplace: false,
            maxFileCount: 1,
            allowedFileExtensions: ["zip", "rar", "7z"],
            browseClass: "btn btn-primary",
            textEncoding: 'UTF-8',
            showUpload: false,
            showCancel: true,
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>"
        });
        $("#inputFile1").fileinput({
            language: 'zh',
            autoReplace: false,
            maxFileCount: 1,
            allowedFileExtensions: ["jpeg", "jpg", "png", "pdf"],
            browseClass: "btn btn-primary",
            textEncoding: 'UTF-8',
            showUpload: false,
            showCancel: true,
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>"
        });

        function se(e) {
            $('#office-pid').val(e.attr('product'));
        }

        function setV(e) {
            $('#product').val(e.attr('product'));
            $('#extension_project_type').val(e.attr('typea'));
            $('#renew_apply_person').val(e.attr('applicant'));
        }

        function set(e) {
            $('#p').val(e.attr('rel'));
            $('#pro').val(e.attr('pid'));
            $('#address').val(e.attr('address'));
        }

        function setReport(e) {
            $('#upload-pro').val(e.attr('product'));
        }

        function ajxZip(e) {
            $.ajax({
                url: '{{url("user/mine/ajxZip")}}',
                type: 'post',
                dataType: "json",
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                data: {
                    'id': e.attr('product')
                },
                success: function (data) {
                    window.location.href = data;
                }

            });
        }

        function s(e) {
            $('#download-a').attr('rel', e.attr('product'))
            var list = eval(e.next().text());
            var size = list.length;
            var tb = $('#file-downloads');
            tb.empty();
            if (size == 0) {
                tb.append('<tr>');
                tb.append('<td class="text-muted" style="background-color: white" colspan="4"><h3 align="center">暂无数据</h3></td>');
                tb.append('</tr>');
            }
            for (var i = 0; i < size; i++) {
                if (list[i]['yn']!=1){
                    var yn="未读";
                }
                else {
                    var yn="已读";
                }
                tb.append('<tr>');
                tb.append('<td class="text-muted" style="text-align: center;padding-top: 10px;">' + (i + 1) + '.</td>');
                tb.append('<td class="mailbox-name" style="text-align: center;padding-top: 10px;">' + list[i]['name'] + '</td>');
                tb.append('<td class="mailbox-name" style="text-align: center;padding-top: 10px;">' + yn + '</td>');
                tb.append('<td class="mailbox-date" style="text-align: center;padding-top: 10px;">' + formatDate(list[i]['created_at']) + '</td>');
                tb.append("<td onclick='test("+ list[i].id+");' class='mailbox-subject' style='text-align: center;padding-top: 10px;'><a href='" + getUrl(list[i]['url']) + "'><i class='fa fa-download' style='color: #009aff;cursor: pointer'></i></a></td>");
                tb.append('</tr>');
            }
            test = function (id){

                console.log(id);

                $.ajax({
                    type: 'POST',
                    url: '{{url('user/mine/yes')}}',
                    data: { id:id, _token:"{{csrf_token()}}"},
                    dataType: 'json',
                    success: function(data){
                        console.log(data);
                    },
                    error: function(xhr, status, error){
                        console.log(xhr);
                        console.log(status);
                        console.log(error);
                    }
                });
            }
        }

        /**
         * 格式化时间
         * @param str
         * @returns {string}
         */
        function formatDate(str) {
            var date = new Date(str);
            return date.getFullYear() + '-' + date.getMonth() + '-' + date.getDay();
        }

        function getUrl(str) {
            var url = window.location.href;
            var arr = url.split("user");
            return arr[0] + "Uploads/resources/" + str;
        }
        function ss(e) {
            $('#trackingNumber').val(e.attr('rel'));
        }
    </script>
@stop